pipeline {
    agent { node { label 'build'} }
    options {
        disableConcurrentBuilds()
        buildDiscarder(logRotator(numToKeepStr:'5'))
    }
    environment{
        SPRING_DATASOURCE_URL = "jdbc:mysql://localhost/shadow_fiend"
    }

    stages {
        stage("Checkout Code") {
            steps {
                git branch: 'master',
                        url: 'https://gitee.com/hongzhiyuanzj_615/shadowfiend.git'
            }
        }

        stage("Build") {
            steps {
                sh "chmod 700 gradlew"
                sh "./gradlew clean flywayClean flywayMigrate build -x test --refresh-dependencies -Pflyway.url=${SPRING_DATASOURCE_URL}"
            }
        }

        stage("Test") {
            steps {
                sh "./gradlew test"
            }
        }
    }
}